<?php
class Reply extends CI_Controller {
	
	public function __construct() {
		parent::__construct ();
		$this->load->model('reply_model');
		$this->load->model('feed_model');
		$this->load->model('user_model');
		$this->load->model('notification_model');
		$this->load->library('datelib');
	}
	
	
	public function add(){
		$uid = $this->session->userdata('user_id');
		$pid = $this->input->post('pid');
		$content = $this->input->post('content');
		$rid = $this->reply_model->add_reply($uid,$pid,$content);
		echo $rid;
		$this->_send_reply_notification($uid, $pid);
	}
	
	public function relpy_list(){
		$pid = $this->input->get('pid');
		$data['replys'] =$this->reply_model->get_reply($pid);
		$this->load->view('reply/list',$data);
	}
	
	function _send_reply_notification($uid,$pid){
		//FIXME 自己的评论不显示
		$feed = $this->feed_model->get($pid);
		$user = $this->user_model->get_user($uid);
		global $type_map;
		if ($feed&&$user) {
			$this->notification_model->add(
					$feed['author'],
					$user['uname'].'对您'.$type_map[$feed['type']].'发表了评论',
					base_url('index.php/blog/index/'.$feed['bid'].'#f'.$pid)
			);
		}
		
	}
}

?>